//package com.ants.platform.core.plugins.redis;
//
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.InitializingBean;
//import org.springframework.beans.factory.annotation.Value;
//import redis.clients.jedis.JedisPoolConfig;
//import redis.clients.jedis.JedisShardInfo;
//import redis.clients.jedis.ShardedJedis;
//import redis.clients.jedis.ShardedJedisPool;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * 手动注入获取连接
// * <dependency>
// *  <groupId>redis.clients</groupId>
// *  <artifactId>jedis</artifactId>
// *  <version>2.8.0</version>
// *  <type>jar</type>
// *  <scope>compile</scope>
// * </dependency>
// * 集群负载均衡Redis
// * Created by liushun on 2016/7/21.
// */
//public class ShardedRedisParams implements InitializingBean {
//
//    private static final Logger logger = LoggerFactory.getLogger(ShardedRedisParams.class);
//
//    private ShardedJedis shardedJedis;
//
//    @Value("${redis.host:}")
//    private String host;
//
//    @Value("${redis.port:6379}")
//    private int port;
//
//    @Value("${redis.timeOut:10000}")
//    private int timeOut;
//
//    @Value("${redis.auth:}")
//    private String auth;
//
//    @Value("${redis.pool.maxActive:1024}")
//    private int maxActive;
//
//
//    @Value("${redis.pool.maxIdle:200}")
//    private int maxIdle;
//
//
//    @Value("${redis.pool.maxWait:1000}")
//    private int maxWait;
//
//
//    @Value("${redis.pool.testOnBorrow:false}")
//    private boolean testOnBorrow;
//
//
//    @Value("${redis.pool.testOnReturn:true}")
//    private boolean testOnReturn;
//
//    //初始化集群 Jedis
//    private void InitShardedRedisManager() {
//        JedisPoolConfig config = new JedisPoolConfig();
//        config.setMaxTotal(maxActive);
//        config.setMaxIdle(maxIdle);
//        config.setMaxWaitMillis(maxWait);
//        config.setTestOnBorrow(testOnBorrow);
//        config.setTestOnReturn(testOnReturn);
//        ShardedJedisPool shardedJedisPool = null;
//        try {
//            String[] hs = host.split(",");
//            List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
//            for (String h : hs)
//                shards.add(new JedisShardInfo(h, port));
//            shardedJedisPool = new ShardedJedisPool(config, shards); //初始化切片池
//            shardedJedis = shardedJedisPool.getResource();
//        } catch (Exception e) {
//            throw new RuntimeException("连接集群 Redis 配置参数错误连接失败，请认真检查配置 :: " + e.getMessage());
//        }
//    }
//
//    public void afterPropertiesSet() throws Exception {
//        if (StringUtils.isEmpty(host))
//            throw new RuntimeException("加载Redis配置失败，配置文件中却没有配置Redis主机: redis.host");
//        else {
//            InitShardedRedisManager();
//            logger.info("\n=============================================================================================" +
//                    "\n=========================== 连接 " + host + " 初始化 Redis 成功!" +
//                    "\n=============================================================================================");
//        }
//
//    }
//}
